For Facebook login in android, first of all, register your app.
Registering Your Facebook App
Step 1: First you log in using your Facebook account to https://developers.facebook.com/apps/.
Step 2: Click on create a new app. And set the app name and the email id as shown in the below pic.
Step 3: You shall see the dashboard in the next screen. Choose Facebook Login Setup and select the platform as Android as shown in the below images.
Step 4: After that, add the following dependencies in your app‘s build.gradle.
buildscript { repositories {
mavenCentral()
}
}
Step 5: Use the latest version of the SDK dependency.
implementation 'com.facebook.android:facebook-android-sdk:4.31.0' or implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
Step 6: To check the SDK is successfully added in our project add the following import statements in your MainActivity.java class file as shown below. If there’s no error, the build was successful.
Step 8: Enter your package name and default activity name with the fully qualified path as shown below. After saving click on Use this package name to confirm.
Step 9: The next window asks for the add key hashes. That can be done by running the following commands on windows cmd.
Sahil Arora
09-Oct-2018Arti Mishra
20-Sep-2018For Facebook login in android, first of all, register your app.
Registering Your Facebook App
Step 1: First you log in using your Facebook account to https://developers.facebook.com/apps/.
Step 2: Click on create a new app. And set the app name and the email id as shown in the below pic.
Step 3: You shall see the dashboard in the next screen. Choose Facebook Login Setup and select the platform as Android as shown in the below images.
Step 4: After that, add the following dependencies in your app‘s build.gradle.
Step 5: Use the latest version of the SDK dependency.
Step 6: To check the SDK is successfully added in our project add the following import statements in your MainActivity.java class file as shown below. If there’s no error, the build was successful.
Step 7: Add your Facebook App ID in the string.xml file.
Step 8: Enter your package name and default activity name with the fully qualified path as shown below. After saving click on Use this package name to confirm.
Step 9: The next window asks for the add key hashes. That can be done by running the following commands on windows cmd.
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\USERNAME\.android\debug.keystore" | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" sha1 -binary | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" base64
You will need the following steps for generating a hash key.
1. Download OpenSSL library for Windows from the https://code.google.com/archive/p/openssl-for-windows/downloads.
2. Open your java bin path location and copy it. And after that open cmd and write some command .
Cd C:\Program Files\Java\jdk-9.0.4\bin (click enter)
Write some key tool command-
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\msclient009\.android\debug.keystore" | "C:\openssl-0.9.8e_X64\bin\openssl" sha1 -binary | "C:\openssl-0.9.8e_X64\bin\openssl" base64
Above command will generate a 28-character key hash unique to your development environment. And after that add key hashes in your Facebook page.
Step 10: Add internet permissions in the AndroidManifest.xml file by adding the following line in the manifest file.
<uses-permission android:name="android.permission.INTERNET"/>
Step 11: Add Following meta-data tag in your AndroidManifest.xml file.
Step 12: Add some code in your activity_main.xml file
MainActivity.java file